<template>
    <div class="container-content">
        <el-form
            ref="elForm"
            :model="formData"
            :rules="rules"
            size="medium"
            label-width="100px"
        >
            <el-form-item label="联系新增" prop="isContinuousAdd" required>
                <el-switch v-model="formData.isContinuousAdd"></el-switch>
            </el-form-item>
            <el-form-item label="创建人" prop="userId">
                <el-input
                    v-model="formData.userId"
                    placeholder="请输入创建人"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <el-form-item label="名称" prop="name">
                <el-input
                    v-model="formData.name"
                    placeholder="请输入名称"
                    clearable
                    :style="{ width: '100%' }"
                ></el-input>
            </el-form-item>
            <el-form-item label="编码" prop="code">
                <el-input
                    v-model="formData.code"
                    placeholder="请输入编码"
                    clearable
                    :style="{ width: '100%' }"
                ></el-input>
            </el-form-item>

            <el-form-item label="父级" prop="parentId">
                <el-input
                    v-model="formData.parentId"
                    placeholder="请输入父级"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <el-form-item label="描述" prop="describe">
                <el-input
                    v-model="formData.describe"
                    type="textarea"
                    placeholder="请选择描述"
                    :autosize="{ minRows: 4, maxRows: 4 }"
                    :style="{ width: '100%' }"
                ></el-input>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import { add } from "@/api/base/data";
import { updataKingBaseSupplierGroupList,editKingBaseSupplierGroupList } from "@/api/bim/outher";
export default {
    components: {},
     props: ["id"],
    data() {
        return {
            flag:false,
            formData: {
                name: "",
                code: undefined,
                userId: undefined,
                parentId: undefined,
                describe: undefined,
                isContinuousAdd: false,
            },
            rules: {
                name: [
                    {
                        required: true,
                        message: "请输入名称",
                        trigger: "blur",
                    },
                ],
                code: [
                    {
                        required: true,
                        message: "请输入编码",
                        trigger: "blur",
                    },
                ],
                userId: [
                    {
                        required: true,
                        message: "请输入创建人",
                        trigger: "blur",
                    },
                ],
                parentId: [
                    {
                        required: true,
                        message: "请输入父级",
                        trigger: "blur",
                    },
                ],
                describe: [
                    {
                        required: true,
                        message: "请选择描述",
                        trigger: "blur",
                    },
                ],
            },
        };
    },
    computed: {},
    watch: {},
    created() {},
    mounted() {
        if (this.id!='') {
            updataKingBaseSupplierGroupList(this.id).then(res=>{
                this.formData=res.data
                this.flag=true
            })
        }
    },
    methods: {
        submitForm(cb) {
           if (this.flag) {
             this.$refs["elForm"].validate((valid) => {
                if (!valid) return;
                // TODO 提交表单
                editKingBaseSupplierGroupList(this.formData, "KingBaseSupplierGroup").then((res) => {
                    if (res.code === 200) {
                        cb();
                        this.$message.success("修改成功");
                        this.flag=false
                    }
                });
            });
           }else{
             this.$refs["elForm"].validate((valid) => {
                if (!valid) return;
                // TODO 提交表单
                add(this.formData, "KingBaseSupplierGroup").then((res) => {
                    if (res.code === 200) {
                        cb();
                        this.$message.success("新增成功");
                    }
                });
            });
           }
        },
        resetForm() {
            this.$refs["elForm"].resetFields();
        },
    },
};
</script>
<style></style>
